﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetCar
{
    class Program
    {
        static void Main(string[] args)
        {
            CarFactory TheCarFactory = ConcreteCarFactory.GetCarFactory;

            List<Client> Clients = new List<Client>();

            Console.WriteLine("Here is where you can order a car!");
            Console.WriteLine("Choose what you wanna do:");
            Console.WriteLine(" 1. I want to see clients");
            Console.WriteLine(" 2. I want to add a client");
            Console.WriteLine(" 3. I want to see cars for client");
            Console.WriteLine(" 4. I want to order a Car for Client");
            Console.WriteLine(" 5. I want to put back a car from Client");
            Console.WriteLine(" Enter \"stop\" for exiting");

            Console.WriteLine("\nYour option: ");
            String UserOption = Console.ReadLine();

            while (UserOption != "stop")
            {
                String ClientFName;
                String ClientLName;
                int ok;

                switch (UserOption)
                {
                    case "1":
                        Console.WriteLine("\nYou have chosen to see clients");
                        if (Clients.Count == 0)
                        {
                            Console.WriteLine("There are no clients!");
                            break;
                        }
                        foreach (Client client in Clients)
                            Console.WriteLine(client.GetFName() + " " + client.GetLName() + " " + client.GetAge());

                        break;

                    case "2":
                        Console.WriteLine("\nYou have chosen to add a client.");
                        Console.WriteLine("Client first name: ");
                        ClientFName = Console.ReadLine();
                        Console.WriteLine("Client last name:");
                        ClientLName = Console.ReadLine();
                        Console.WriteLine("Client age: ");
                        String ClientAge = Console.ReadLine();

                        Client NewClient = new Client(TheCarFactory, ClientFName, ClientLName, ClientAge);
                        Clients.Add(NewClient);
                        Console.WriteLine("Client successfully added");

                        break;

                    case "3":
                        ok = 0;
                        Console.WriteLine("You have chosen to see cars for client");
                       
                        if (Clients.Count == 0)
                        {
                            Console.WriteLine("There are no clients!");
                            break;
                        }

                        Console.WriteLine("Client first name: ");
                        ClientFName = Console.ReadLine();
                        Console.WriteLine("Client last name:");
                        ClientLName = Console.ReadLine();

                        if (Clients.Count == 0)
                        {
                            Console.WriteLine("There are no clients!");
                            break;
                        }

                        foreach (Client client in Clients)
                            if (client.GetFName() == ClientFName && client.GetLName() == ClientLName)
                            {
                                ok = 1;
                                client.PrintCarList();
                            }

                        break;

                    case "4":
                        Console.WriteLine("I want to order a car for client");
                        Console.WriteLine("Client's first name: ");
                        ClientFName = Console.ReadLine();
                        Console.WriteLine("Client's last name: ");
                        ClientLName = Console.ReadLine();
                        ok = 0;

                        foreach (Client client in Clients)
                        {
                            if (client.GetFName() == ClientFName && client.GetLName() == ClientLName)
                            {
                                String CarType;
                                String CarColour;
                                String CarTransmission;
                                String CarMoto;

                                Console.WriteLine("Car type: mini/sedan/coupe");
                                CarType = Console.ReadLine();
                                Console.WriteLine("Car colour: (red/blue)");
                                CarColour = Console.ReadLine();
                                Console.WriteLine("Car transmission: (manual/automatic)");
                                CarTransmission = Console.ReadLine();
                                Console.WriteLine("Car fuel: (gas/diesel)");
                                CarMoto = Console.ReadLine();

                                ok = 1;

                                client.CommandCar(CarType, CarColour, CarTransmission, CarMoto);
                                break;
                            }
                        }

                        if (ok == 0)
                            Console.WriteLine("The client does not exist!");
                        else
                            Console.WriteLine("Car successfully added to client's list");

                        break;

                    case "5":
                        Console.WriteLine("You have chosen to put back car for client");

                        Console.WriteLine("Client first name: ");
                        ClientFName = Console.ReadLine();
                        Console.WriteLine("Client last name:");
                        ClientLName = Console.ReadLine();

                        ok = 0;

                        foreach (Client client in Clients)
                        {
                            if (client.GetFName() == ClientFName && client.GetLName() == ClientLName)
                            {
                                ok = 1;

                                Console.WriteLine("Client car number: ");
                                String CN = Console.ReadLine();
                                int CarNumber = Convert.ToInt32(CN);

                                client.ReturnCar(CarNumber - 1);

                                break;
                            }
                        }

                        if (ok == 0)
                            Console.WriteLine("The client does not exist!");
                        else
                            Console.WriteLine("Car successfully put back");

                        break;

                    default:
                        break;
                }

                Console.WriteLine("\nYour option: ");
                UserOption = Console.ReadLine();
            }
        }
    }
}
